package gui;

import java.awt.Graphics;
import java.awt.Image;
import java.io.IOException;

import javax.imageio.ImageIO;

public class ImagenPrincipal extends Imagen {

        private Image original;
        private String url;
        
        public ImagenPrincipal (String ruta,int xOriginal, int yOriginal, int xActual, int yActual){
                try {
                        super.setImagen(ImageIO.read (getClass().getClassLoader().getResource(ruta)));
                        original = ImageIO.read (getClass().getClassLoader().getResource(ruta));
                } catch (IOException e) {
                        // TODO Auto-generated catch block
                        e.printStackTrace();
                }
        	//nuevo
        	url=ruta;
        	
                super.setXOriginal(xOriginal);
                super.setYOriginal(yOriginal);
                super.setXActual(xActual);
                super.setYActual(yActual);
        }
        
        public ImagenPrincipal (String ruta,int xOriginal, int yOriginal, int xActual, int yActual,int x, int y){
            try {
                    super.setImagen(ImageIO.read (getClass().getClassLoader().getResource(ruta)));
                    original = ImageIO.read (getClass().getClassLoader().getResource(ruta));
            } catch (IOException e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
            }
        	url=ruta;
            super.setXOriginal(xOriginal);
            super.setYOriginal(yOriginal);
            super.setXActual(xActual);
            super.setYActual(yActual);
            super.setImagen(original.getScaledInstance(x, y, Image.SCALE_SMOOTH));
    }
        
        @Override
        public void actualizar(int xNueva, int yNueva) {
                // TODO Auto-generated method stub
        	//try {
              //  super.setImagen(ImageIO.read (getClass().getClassLoader().getResource(url)));
                //original = ImageIO.read (getClass().getClassLoader().getResource(url));
        		//} catch (IOException e) {
                // TODO Auto-generated catch block
                //e.printStackTrace();
        		//}
                double x = new Double(xNueva)/new Double(super.getXOriginal());
                double y = new Double(yNueva)/new Double(super.getYOriginal());
                Image aux = super.getImagen();
                super.setImagen(original.getScaledInstance((int) (Math.round(aux.getWidth(null)*x)),(int) (Math.round(aux.getHeight(null)*y)), Image.SCALE_SMOOTH));
                super.setXOriginal(xNueva);
                super.setYOriginal(yNueva);
                super.setXActual((int) (Math.round(super.getXActual()*x)));
                super.setYActual((int) (Math.round(super.getYActual()*y)));
        }

        @Override
        public void pintar(Graphics g) {
                // TODO Auto-generated method stub
        	//System.out.println("Va a pintar");
        	//try {
              //  super.setImagen(ImageIO.read (getClass().getClassLoader().getResource(url)));
               // original = ImageIO.read (getClass().getClassLoader().getResource(url));
        		//} catch (IOException e) {
                // TODO Auto-generated catch block
                //e.printStackTrace();
        		//}
                if(g != null){                   
              //  	System.out.println("Pinta");
                	g.drawImage(super.getImagen(),super.getXActual(),super.getYActual(), null);
                }
        }
        
        public void quitarImagen(){
        	this.original=null;
        	super.imagen=null;
        	
        }
        
        

}

